﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using project.General;
using project.Models;
using PagedList;


namespace project.Areas.Admin.Controllers
{
    public class EdittagsController : Controller
    {
        //
        // GET: /Admin/Edittags/
        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Admin/Edittags/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Admin/Edittags/Create
        public ActionResult Create()
        {

          
            return View();
        }

        //
        // POST: /Admin/Edittags/Create
        [HttpPost]
        public string Create(string name, string slug, string des)
        {
            try
            {

                    Term s = new Term();
               
                    s.Name = name;
                    s.Slug = slug;
                    General.DataClass.ThemDanhMuc(s);
                    //ModelState.AddModelError("Thông Báo","Thêm Thành công");
                    return "Thêm thành công";              
            }
            catch
            {
                return "thêm bị lỗi";
            }

        }

        public ActionResult AjxaGetCategory(int? page= 1)
        {
            var data = General.DataClass.db.Terms.OrderByDescending(s=>s.Term_id).ToList();
            int pagesize = 10;
            int pagenumber =(page??1);
            return View(data.ToPagedList(pagenumber,pagesize));
        }

        //
        // GET: /Admin/Edittags/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Admin/Edittags/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Admin/Edittags/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Admin/Edittags/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
